<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
	<title></title>
	<meta name="format-detection" content="telephone=no"/>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../css/list.css" />
	<style>
	.shopnameNew {color: #999; /*line-height: 16px;*/ font-size: 1.3em; font-weight: bold; padding-bottom: 2px; padding-top: 3px; display: inline-block;}
	</style>
</head>
<body>
	<div class="h10"></div>	  
	<div id="main_content">
	
		<!--<div class="main_content" style="padding:15px 0px;">
	           <div class="shopname hot-title"  style="color:#999;padding-left:2%;width: 88%;" tapmode="presshover">fgfhgfh
	         </div><div class="right"><img src="../image/btn/right.png" /></div></div>-->
	
	</div>
  	<div id="divNoDataTip">
		<div id="textTip" style="margin-top:10px;margin-bottom:10px;width:100%;text-align: center;" 
			class="button red" tapmode="">正在加载..</div>
	</div> 
	<div class="h10"></div>
	<input id="pageIndex" type="hidden" value="0"/>
	<input id="pageSize" type="hidden" value="20"/>
</body>
<script type="text/javascript" src="../script/api.js"></script>  
<script type="text/javascript" src="../script/alpenlicebe.js"></script>   
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hashes.min.js"></script> 
<script>
	apiready = function(){ 
 		/*下拉刷新*/
    	api.setRefreshHeaderInfo({
            visible: true,
            loadingImg: 'widget://image/refresh.png',
            bgColor: '#fff',
            textColor: '#000',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function (ret, err) { 
        	$("#pageIndex").val(0); 
        	$("#main_content").html(""); 
        	$("#textTip").html("正在加载..");
            goto_loadDataFun();
            api.refreshHeaderLoadDone();
        }); 
        
       	/*滑动到底部加载数据*/
   		api.addEventListener({name: 'scrolltobottom'}, function (ret, err) {
            goto_loadDataFun();
        });  
        
        /*初始化加载数据*/
       	goto_loadDataFun();   
	}  
	
    function goto_loadDataFun() {  
        goto_loadNewsListFun(); 
        api.parseTapmode();  
    } 
	function goto_loadNewsListFun(){  
		var userID=Alpe_getLocalStorge('access_token');  
    	if(''==userID){
    		api.alert({title:'系统提示',msg:'您未登录'});
			return;
    	}
    	var cateID=api.pageParam.cateID;
    	var cateName=api.pageParam.cateName;
    	var cateInfo=api.pageParam.cateInfo;
		if(''==cateID||undefined==cateID||null==cateID
		||''==cateInfo||undefined==cateInfo||null==cateInfo){
    		api.alert({title:'系统提示',msg:'参数错误'});
			return;
    	}
		var pageIndex=parseInt($("#pageIndex").val())+1;
		var pageSize=$("#pageSize").val();
		$("#pageIndex").val(pageIndex);
		 
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '',
		    text: '',
		    modal: false
		});
		
		var MD5 = new Hashes.MD5;   
       	var access_token = Alpe_getLocalStorge("access_token");                     
       	var admin_id = Alpe_getLocalStorge("admin_id"); 
       	var sign = MD5.hex(access_token+admin_id+pageIndex+cateInfo+'1.0syjqingbao');
            
       	var url = Alpe_ApiUrl+'r='+cateInfo+'&access_token='+access_token+'&admin_id='+admin_id
       		+'&page='+pageIndex+'&pagesize='+pageSize
       		+'&v=1.0&sign='+sign;
       		//console.log(url);
       	api.ajax({
	         url: url,
	         method: 'get',
	         cache: false,
	         timeout: 30,			
	         dataType: 'json'
       	}, function(ret, err){ 
			if (ret) {	 
				if(ret.success == '100'){ 
					if(ret.list.length<pageSize){
						api.removeEventListener({name:'scrolltobottom'}); 
                 		$("#textTip").html("暂无更多数据");
					}   	
	            	$.each(ret.list, function (index, v) {
	            		var colorTitle='';
						var tempID=Alpe_getLocalStorge('sys_baogao_tempID_'+v.message_id);
						
						if(tempID!=''){
							colorTitle = "color:#999;";
						}
						/*console.log(tempID+'*********'+v.message_id+'-----'+colorTitle);*/
	            		var tmpHtml='<div class="main_content" style="padding:15px 0px;">'
	            			+'<div id="newTitleID_'+v.message_id+'" class="shopname hot-title" style="'+colorTitle+'padding-left:2%;width: 88%;" onclick="goto_downFileFun('+v.message_id+',\''+v.upfile_path+'\')" tapmode="presshover">'+v.title
	            			+'</div><div class="right"><img src="../image/btn/right.png" /></div></div>'
				   		$("#main_content").append(tmpHtml);				   	                                             	                                            		     
					}); 
				}else if("002"==ret.success||"003"==ret.success){ 
					goto_openWin_loginWin(ret.message);
				}else{	
					api.removeEventListener({name:'scrolltobottom'}); 
                 	$("#textTip").html(ret.message);			 
					api.toast({
		         		msg: ret.message,
                 		duration:2000,
                    	location: 'middle'
               		});         
		  		}
		  		api.hideProgress();
			}else{
				api.alert({title:'系统提示',msg:'错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode});
				api.hideProgress();
			} 
   		});
	}
 
	function goto_downFileFun(downID,downUrl){    
		Alpe_setLocalStorge('sys_baogao_tempID_'+downID,downID);
 		$("#newTitleID_"+downID).css('color','#999');
 		   		    
		var tmpFile = Alpe_getLocalStorge(downID);
		if(''==tmpFile||null==tmpFile||undefined==tmpFile){
			api.confirm({
                 title: '下载提醒',
                 msg: '文件不在本地是否需要下载?',
                 buttons:['确定', '取消']
             },function(ret,err){
                 if(ret.buttonIndex == 1){
                	api.download({
					    url: downUrl,
					    savePath: 'fs://testDown/'+downID+'.pdf',
					    report: true,
					    cache: true,
					    allowResume:true
					},function(ret,err){
					    if (1==ret.state) { 
					    	Alpe_setLocalStorge(downID,ret.savePath);
					        var obj = api.require('pdfReader');
			                obj.open({
			             		path:ret.savePath
			                }); 
					    } 
					    if (2==ret.state) {
					        alert(err.msg);
					    } 
					});
                 }
             });
		}else{
			var obj = api.require('pdfReader');
     		obj.open({
           		path:tmpFile
        	});
		} 	 
	} 
</script>
</html>